<%@ CodePage = "65001" %>
<!--#include file="..\class\QL.Aes.asp"-->
<!--#include file="_html_entity.asp"-->
<!--#include file="_file_access.asp"-->
<!--#include file="_http.asp"-->
<!--#include file="_encoder.asp"-->
<!--#include file="..\class\clsAccessHelper.asp"-->
<!--#include file="..\class\HashTable.asp"-->
<!--#include file="..\class\CList.asp"-->
<%
'Extent Language
Public Function IIf(expression, truepart, falsepart)
  If expression = True Then
    IIf = truepart
  Else
    IIf = falsepart
  End If
End Function

Public Function IsBlank(text)
  If text = Empty or text = "" then
    IsBlank = True
  Else
    IsBlank = False
  End If
End Function

Public Function FormatDate(adate, matchcode)
  Dim year_month_date
  Dim hour_minutes
  Dim seconds

  year_month_date = Year(adate) & "-" & DoubleDigitStr(Month(adate)) & "-" & DoubleDigitStr(Day(adate))
  hour_minutes = DoubleDigitStr(Hour(adate)) & ":" & DoubleDigitStr(Minute(adate))
  seconds = Second(adate)
  Select Case matchcode
    Case "yyyy-MM-dd HH:mm:ss"
      FormatDate = year_month_date & " " & hour_minutes & ":" & seconds
    Case "yyyy-MM-dd HH:mm"
      FormatDate = year_month_date & " " & hour_minutes
    Case Default
      FormatDate = year_month_date & " " & hour_minutes & ":" & seconds
  End Select
End Function

Public Function DoubleDigitStr(s)
  If Len(s) > 2 Then
    DoubleDigitStr = Mid(s, 1, 2)
  Else
    DoubleDigitStr = RJust(s, 2, "0")
  End If
End Function

Public Function RJust(text, length, prechar)
  Dim rtext
  rtext = text
  If length > 0 Then
    If Len(text) < length Then
      rtext = String(length - Len(text), prechar) & text
    End If
  End If
  RJust = rtext
End Function

'Web Function


Public Function Form_To_Value(field, request_type, value_type)
  Dim data
  If request_type = "f" Then
    If Request.Form(field).Count > 0 Then
      data = Request.Form(field)(1)
    Else
      data = vbNullString
    End If
  ElseIf request_type = "q" Then
    data = Request.QueryString(field)
  Else
    data = vbNullString
  End If
  Select Case value_type
    Case "string"
      If isEmpty(data) = True Then
        form_to_value = vbNullString
      Else
        form_to_value = CStr(data)
      End If
    Case "integer"
      If isEmpty(data) = True Then
        form_to_value = 0
      Else
        form_to_value = CInt(data)
      End If
    Case "decimal"
      If isEmpty(data) = True Then
        form_to_value = 0.0
      Else
        form_to_value = CDec(data)
      End If
    Case "currency"
      If isEmpty(data) = True Then
        form_to_value = 0.0
      Else
        form_to_value = CCur(data)
      End If
  End Select
End Function

Public Function TryEncode(Byval szInput)
  Dim hash
  Set hash = New HashTable
  TryEncode = hash.UTF8_URLEncoding(szInput)
  Set hash = Nothing
End Function

Public Function TryDecode(Byval szInput)
  Dim hash
  Set hash = New HashTable
  TryDecode = hash.UTF8_UrlDecode(szInput)
  Set hash = Nothing
End Function

Public Function ToURL()
  Dim hash
  Set hash = New HashTable
  hash.Item("param1") = 4
  hash.Item("param2") = "windows"
  hash.Item("paramxx") = "天气真好"
  ToURL = hash.ToURLParams(Array("paramxx","param2","param1"))
  Set hash = Nothing
End Function

Public Function DisplayArr()
  Dim hash, ret
  Set hash = New HashTable
  hash.Item("param1") = 4
  hash.Item("param2") = "windows"
  hash.Item("paramxx") = "天气真好"
  ret = hash.ToArray
  Set hash = Nothing
End Function

Public Function ExistsKey()
  Dim hash
  Set hash = New HashTable
  hash.Item("param1") = 4
  hash.Item("param2") = "windows"
  ExistsKey= hash.Values().Item(1)
  'stop
  Set hash = Nothing
End Function

Public Function TryNewCkl()
  Dim list
  Set list = New CList
  list.DistinctAdd "2"
  list.DistinctAdd "2"
  list.DistinctAdd "4"
  TryNewCkl = list.Join(",", 1)
  Set list = Nothing
End Function

Public Function TryReadDB()
  Dim db, dbFilePath, mRes
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  Set mRes = db.ExecQuery("SELECT `FuncID`,`FuncName`,`FuncType`,`CodeType`,`CreateTime`,`CreatorMail`,`Code`,`Likes`,`LastLikeIP` FROM `Functions`")
  'Stop
  TryReadDB = mRes.RecordCount
  Set mRes = Nothing
End Function

Public Function TryParamReadDB()
  Dim db, dbFilePath, mRes
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  Set mRes = db.ExecParamQuery("SELECT `FuncID`,`FuncName`,`FuncType`,`CodeType`,`CreateTime`,`CreatorMail`,`Code`,`Likes`,`LastLikeIP` FROM `Functions` WHERE `FuncID` = ?", Array(37))
  'Stop
  TryParamReadDB = mRes.RecordCount
  Set mRes = Nothing
End Function

Public Function TryNamedReadDB()
  Dim db, dbFilePath, mRes, hash
  Set db = New clsAccessHelper
  Set hash = New HashTable

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  hash.Item("FuncID") = 37
  Set mRes = db.ExecNamedQuery("SELECT `FuncID`,`FuncName`,`FuncType`,`CodeType`,`CreateTime`,`CreatorMail`,`Code`,`Likes`,`LastLikeIP` FROM `Functions` WHERE `FuncID` = @FuncID", hash)
  'Stop
  TryNamedReadDB = mRes.RecordCount
  Set mRes = Nothing
  Set hash = Nothing
End Function

Public Function TryNonQuery()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryNonQuery = db.ExecNonQuery("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows','code')")

  Set db = Nothing
End Function

Public Function TryParamNonQueryDB()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryParamNonQueryDB = db.ExecParamNonQuery("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows',?)", Array(CStr(Year(Now))))
  Set db = Nothing
End Function

Public Function TryNamedNonQueryDB()
  Dim db, dbFilePath, hash
  Set db = New clsAccessHelper
  Set hash = New HashTable

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  hash.Item("type") = "functionshaha"
  TryNamedNonQueryDB = db.ExecNamedNonQuery("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows',@type)", hash)
  Set hash = Nothing
  Set db = Nothing
End Function

Public Function TryCreate()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryCreate = db.ExecCreate("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows','code')")

  Set db = Nothing
End Function

Public Function TryParamCreate()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryParamCreate = db.ExecParamCreate("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows',?)", Array(CStr(Minute(Now))))
  Set db = Nothing
End Function

Public Function TryNamedCreate()
  Dim db, dbFilePath, hash
  Set db = New clsAccessHelper
  Set hash = New HashTable

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  hash.Item("type") = "functionshaha"
  TryNamedCreate = db.ExecNamedCreate("INSERT INTO `Functions`(`FuncName`,`FuncType`) VALUES('windows',@type)", hash)
  Set hash = Nothing
  Set db = Nothing
End Function

Public Function TryExecScalar()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryExecScalar = db.ExecScalar("SELECT `FuncName` FROM `Functions` WHERE `FuncID` = 181")

  Set db = Nothing
End Function

Public Function TryExecParamScalar()
  Dim db, dbFilePath
  Set db = New clsAccessHelper

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  TryExecParamScalar = db.ExecParamScalar("SELECT `FuncName` FROM `Functions` WHERE `FuncID` = ?", Array(181))
  Set db = Nothing
End Function

Public Function TryExecNamedScalar()
  Dim db, dbFilePath, hash
  Set db = New clsAccessHelper
  Set hash = New HashTable

  dbFilePath = Server.MapPath("..\..\db\func.mdb")
  db.SetConnToSafeDB dbFilePath, "windowsloveubuntu"
  hash.Item("id") = 181
  TryExecNamedScalar = db.ExecNamedScalar("SELECT `FuncName` FROM `Functions` WHERE `FuncID` = @id", hash)
  Set hash = Nothing
  Set db = Nothing
End Function
%>